<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        Object.prototype.freeze = function () {
            dg(this);

            function dg(item) {
                if (typeof item == "object") {
                    Object.freeze(item);
                    for (let key in item) {
                        dg(item[key]);
                    }
                }
            }
        }


        let obj1 = {
            name: 'hzj',
            city: {
                name: '大连'
            }
        }
        let obj2 = deepCopy(obj1);
        console.log(obj2);

        function deepCopy(item) {
            let obj = null;
            if (Array.isArray(item)) {
                obj = [];
            } else if (typeof item == "object") {
                obj = {};
            } else {
                return item;
            }
            for (let key in item) {
                obj[key] = deepCopy(item[key]);
            }
            return obj;
        }
    </script>
</body>

</html>